#pragma once

#include <iostream>
#include <string>
#include "localcommon.hpp"

namespace Local_Reactor
{
    class Reactor;
}

// connection 链接
namespace Local_Connection
{
    using handler_t = std::function<std::string(std::string &)>;

    class LocalConnection
    {
    public:
        /**********构造析构************** */
        LocalConnection() : _events(0), _owner(nullptr) {}
        ~LocalConnection() {}

        /**********virtual************** */
        virtual void Recver() = 0;
        virtual void Sender() = 0;
        virtual void Excepter() = 0;
        virtual int GetsockFd() = 0;
        /**********GetSet************** */
        void SetEvent(const uint32_t &events)
        {
            _events = events;
        }
        uint32_t GetEvent()
        {
            return _events;
        }
        void SetReactor(Local_Reactor::Reactor *owner)
        {
            _owner = owner;
        }
        Local_Reactor::Reactor *GetReactor()
        {
            return _owner;
        }
        /**********回调函数************** */
        void RegisterHandler(handler_t handler)
        {
            _handler = handler;
        }

    private:
        // 回调指针
        Local_Reactor::Reactor *_owner;

        // 关心事件
        uint32_t _events;

    protected:
        // 回调函数指针
        handler_t _handler;
    };
}